package cmd

import (
	"context"
	log "github.com/sirupsen/logrus"
	"github.com/spf13/cobra"
	"mongofix/user"
	"strconv"
	"strings"
)

var mid string
var num int
var UpLimit bool
var convert bool
var userCom = &cobra.Command{
	Use:     "user",
	Short:   "用户管理命令",
	Long:    "用户管理命令",
	Version: "1.0",
	Run: func(cmd *cobra.Command, args []string) {
		if UpLimit {
			midNum, err := strconv.Atoi(strings.Split(mid, ",")[0])
			if err != nil {
				log.Errorf("mid转成正数失败,mid:%v", mid)
				return
			}
			user.UpGroupLimit(context.Background(), num, midNum)
		}
		if convert {
			user.GetUserIdByMid(context.Background(), mid)
		}

	},
}

func init() {
	userCom.Flags().BoolVarP(&UpLimit, "UpLimit", "l", false, "升级用户的加入群限制")
	userCom.Flags().BoolVarP(&convert, "convert", "c", false, "根据Mid转换为uid")

	userCom.Flags().IntVarP(&num, "num", "n", 50, "升级到多少")
	userCom.Flags().StringVarP(&mid, "mid", "m", "", "用户的mid")
	rootCmd.AddCommand(userCom)
}
